<?php

class Model_agen extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->helper('text');
    }

    function get_agen() {
        $sql = "select *
                from user";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $value) {
                $a[] = $value;
            }
            return $a;
        } else {
            return FALSE;
        }
    }

    function get_agen_admin() {
        $sql = "select user_id,nama_depan,email,username,level
                from user";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            return $query;
        } else {
            return FALSE;
        }
    }

    function get_user_detail($str_id = '') {
        if ($str_id == '') {
            return FALSE;
        }
        $sql = "SELECT * FROM user
                where user_id = ?";
        $query = $this->db->query($sql, $str_id);
        if ($query->num_rows() == 1) {
            $value = $query->row();
            return $value;
        } else {
            return FALSE;
        }
    }

    function hapus_user($where = array()) {
        $this->db->trans_begin();
        $this->db->delete('user', $where);
        if ($this->db->trans_status() == FALSE) {
            $this->db->trans_rollback();
            return FALSE;
        } else {
            $this->db->trans_commit();
            return TRUE;
        }
    }

}

?>
